package com.example.stu.controller;

import com.example.stu.entity.Result;
import com.example.stu.service.EmailService;
import com.mysql.jdbc.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.regex.Pattern;

/**
 * @Date: 2021/3/19
 * @Author: 黄先军
 * @Description:
 */
@RestController
@RequestMapping("/email")
public class EmailController {

    @Autowired
    private EmailService emailService;

    @RequestMapping("sendEmail")
    public Result sendEmail(String email){
        if(StringUtils.isNullOrEmpty(email)){
            return new Result(false,"邮箱号不能为空");
        }
         String regex = "\\w+@\\w+\\.[a-z]+(\\.[a-z]+)?";
         if(email.matches(regex)){
             return emailService.sendEmail(email);
         }else{
             return new Result(false,"邮箱格式错误");
         }



    }
}
